//
//  DVDController.m
//  GBKHOME
//
//  Created by XMYY-19 on 2017/9/7.
//
//

#import "DVDController.h"
#import "Global1.h"
#import "ColorButton.h"
#import "LoginController1.h"
#import <QuartzCore/QuartzCore.h>

@interface DVDController ()
- (IBAction)goBackClick:(UIButton *)sender;
- (IBAction)oigClick:(UIButton *)sender;
- (IBAction)menuClick:(UIButton *)sender;
- (IBAction)popViewClick:(UIButton *)sender;
@property (retain, nonatomic) IBOutlet UIButton *otherBtn;
@property (retain, nonatomic) IBOutlet UIButton *goBackBtn;

@property (retain, nonatomic) IBOutlet UIButton *menuBtn1;
@property (retain, nonatomic) IBOutlet UIButton *jinAndOutBtn;

@property(nonatomic,strong)CAGradientLayer *gradientLayer;
- (IBAction)popClick:(UIButton *)sender;

@property(nonatomic,retain) IBOutlet ColorButton *btn;

@property(nonatomic,assign)BOOL isClick;

@property(nonatomic,strong)UIView *dvdPopView;


@property(nonatomic,assign) BOOL isClosed;



@end

@implementation DVDController
-(id)initWithEquipment:(NewEquipment *)equ
{
    self = [super init];
    if (self)
    {
        self.isClosed = NO;
        self.equipment = equ;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setNavigationTitleView:_equipment.name];
    UIImage *image =[UIImage imageNamed:@"mainbg"];
    self.view.layer.contents = (id)image.CGImage;
    [self initWithUI];
    
    
    
    
    NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"dvdPopView" owner:nil options:nil];
    UIView *plainView = [nibContents lastObject];
    
    
    plainView.frame = CGRectMake(0, 667, 375, 667);
    
    self.dvdPopView = plainView;
    
    [self.view addSubview:plainView];
    
    
}
-(void)initWithUI
{
    [self.jinAndOutBtn setTitle:@"进/出仓" forState:UIControlStateNormal];
    [self.jinAndOutBtn setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_nor"] forState:UIControlStateNormal];
    [self.jinAndOutBtn setTitleColor:[UIColor colorWithRGBColorByString:@"#4b4b6c"] forState:UIControlStateNormal];
    [self.jinAndOutBtn addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.jinAndOutBtn setTag:0];
    
    
    
    [self.menuBtn1 setTitle:@"MENU" forState:UIControlStateNormal];
    [self.menuBtn1 setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_nor"] forState:UIControlStateNormal];
    [self.menuBtn1 setTitleColor:[UIColor colorWithRGBColorByString:@"#4b4b6c"] forState:UIControlStateNormal];
    [self.menuBtn1 addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.menuBtn1 setTag:1];
    
    
    
    [self.goBackBtn setTitle:@"" forState:UIControlStateNormal];
    [self.goBackBtn setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_nor"] forState:UIControlStateNormal];
    [self.goBackBtn setTitleColor:[UIColor colorWithRGBColorByString:@"#4b4b6c"] forState:UIControlStateNormal];
    [self.goBackBtn addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.goBackBtn setTag:2];
    
    
    [self.otherBtn setTitle:@"。。。" forState:UIControlStateNormal];
    [self.otherBtn setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_nor"] forState:UIControlStateNormal];
    [self.otherBtn setTitleColor:[UIColor colorWithRGBColorByString:@"#4b4b6c"] forState:UIControlStateNormal];
    [self.otherBtn addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.otherBtn setTag:3];
}
-(void)changebgColor
{
    
}
-(void)btnClick1:(UIButton *)sender
{
    
    
    UIButton *button = sender;
    switch (button.tag) {
        case 0:
            self.jinAndOutBtn = button;
            [self test1:self.jinAndOutBtn];
            break;
        case 1:
            self.menuBtn1 = button;
            [self test1:self.menuBtn1];
            break;
        case 2:
            self.goBackBtn = button;
            [self test1:self.goBackBtn];
            break;
        default:
            self.otherBtn = button;
            [self test1:self.otherBtn];
            break;
    }
    
}

-(void)test1:(UIButton *)btn
{
    if(self.isClick)
    {
        
        
        [btn setTitleColor:[UIColor colorWithRGBColorByString:@"#f8f9fa"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_pre"] forState:UIControlStateNormal];
        self.isClick = NO;
    }
    else
    {
        [btn setBackgroundImage:[UIImage imageNamed:@"btn_baifeng_nor"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRGBColorByString:@"#4b4b6c"] forState:UIControlStateNormal];
        
        self.isClick = YES;
    }
}
- (IBAction)popClick:(UIButton *)sender {
    
    
}
- (void)dealloc {
    [_jinAndOutBtn release];
    [_menuBtn1 release];
    [_goBackBtn release];
    [_otherBtn release];
    [super dealloc];
}

#pragma mark--菜单点击
- (IBAction)goBackClick:(UIButton *)sender
{
    
      [self ctrDVD:@"BACK"];
}

- (IBAction)oigClick:(UIButton *)sender
{
    
    [self ctrDVD:@"OIG"];
}

- (IBAction)menuClick:(UIButton *)sender {
    [self ctrDVD:@"MENU"];
}
#pragma mark - 控制DVD
- (void)ctrDVD:(NSString *)ORDER
{
    NSString *order = ORDER;
    NSString *orderName = NSLocalizedString(order, nil);
    NSString *operat = NSLocalizedString(@"operat:", nil);
    NSString *startTip = [operat stringByAppendingString:orderName];
    [iToast showTip:startTip gravity:iToastGravityBottom];
    [WebServices setShowConnectting:NO];
    self.ctrOrder = order;
       NSString *switchId = @"15";
//    NSString *switchId = self.equipment.switchId;
    NSString *sessionId = [LoginController1 sessionID];
    NSString *fomat = @"[{\"orderId\":\"%@\", \"switchId\":\"%@\", \"sessionId\":\"%@\"}]";
    NSString *body = [NSString stringWithFormat:fomat, order, switchId, sessionId];
    
    //操作失败！原因：
    NSString *errorTip = [OperationTip operatSuccess:NO type:ErrorTypeNetworkFail];
    [WebServices requestStartOrder:@"ctlDVD" body:body target:self action:@selector(ctrDVDEnd:) errorTip:errorTip];
}

- (void)ctrDVDEnd:(NSDictionary *)dic
{
    NSLog(@"%@", dic);
    NSNumber *result = [dic objectForKey:@"result"];
    if (result.integerValue == 0) {
        //操作成功
        NSString *tip = [OperationTip operatSuccess:YES type:ErrorTypeServerReturnFail];
        [iToast showTip:tip gravity:iToastGravityBottom];
    }
    else
    {
        //操作失败！原因：
        NSString *tip = [OperationTip operatSuccess:NO type:ErrorTypeServerReturnFail];
        [iToast showTip:tip gravity:iToastGravityBottom];
    }
}
- (IBAction)popViewClick:(UIButton *)sender {
    [UIView animateWithDuration:1.5 animations:^{
        // 设置view弹出来的位置
       // self.dvdPopView.frame = CGRectMake(-20, 50, 375, 667);
    }];
}
@end
